// $URL: http://mingw-lib.googlecode.com/svn/trunk/local/box/yt_new/main.cpp $
// $Rev: 791 $
// $Author: akio.miyoshi $
// $Date:: 2012-10-23 08:18:20 +0000#$

#include <QtCore>
#include <QtGui>
#include <QtWebKit>
#include "widget.h"
#include "mainwindow.h"
#include "env.h"

// static plugin
// http://doc.trolltech.com/4.6/plugins-howto.html#static-plugins
#ifdef QT_STATIC_BUILD
#include <QtCore>
Q_IMPORT_PLUGIN(qgif)
Q_IMPORT_PLUGIN(qico)
Q_IMPORT_PLUGIN(qjpeg)
Q_IMPORT_PLUGIN(qmng)
Q_IMPORT_PLUGIN(qcncodecs)
Q_IMPORT_PLUGIN(qjpcodecs)
Q_IMPORT_PLUGIN(qkrcodecs)
Q_IMPORT_PLUGIN(qtwcodecs)
//Q_IMPORT_PLUGIN(qsqlodbc)
#endif

int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(yt_dump);
    QApplication a(argc, argv);

    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

    QCoreApplication::setOrganizationDomain("akio.miyoshi");
    QCoreApplication::setOrganizationName("akio.miyoshi");
    QCoreApplication::setApplicationName("yt_dump");
    QSettings settings(
            QSettings::IniFormat, //QSettings::NativeFormat,
            QSettings::UserScope, // QSettings::SystemScope,
            QCoreApplication::organizationName(),
            QCoreApplication::applicationName()
            );
	//settings.setValue("twitpic/username", "dummy-user");
	//settings.setValue("twitpic/password", "dummy-pass");

    QWebSettings *webSettings = QWebSettings::globalSettings();
    webSettings->setAttribute(QWebSettings::JavascriptEnabled, true);
    webSettings->setAttribute(QWebSettings::PluginsEnabled, true);
    webSettings->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true);
    //webSettings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);

    Env v_env;
	//g_Env = &v_env;
    qDebug() << g_Env;
	g_Env->youtubeLogin();
    if(g_Env->youtube_auth_key.isEmpty())
    {
        QMessageBox::information(0, "Login Failed", "Login Failed");
        return 0;
    }

	//MainWindow *mainWindow = new MainWindow(0);
	//g_Env->mainWindow = new MainWindow(0);
	//MainWindow mw;
	//g_Env->mainWindow = &mw;
	//mw.show();

	//qDebug() << g_Env->mainWindow;
	g_Env->mainWindow->show();

    return a.exec();
}
